﻿using IntelligentAgriculture.Contracts.Dto.Output;
using IntelligentAgriculture.Contracts.Interface;
using IntelligentAgriculture.WebAPI.Application.Command.RoleCommand;
using MediatR;

namespace IntelligentAgriculture.WebAPI.Application.CommandHandler.RoleCommandHandler
{
    public class RoleSelectCommandHandler : IRequestHandler<RoleSelectCommand, Results<List<RoleSelectOutput>>>
    {
        private readonly IRoleService _roleService;
        public RoleSelectCommandHandler(IRoleService roleService)
        {
            _roleService = roleService;
        }
        /// <summary>
        /// 处理角色选择命令，从角色服务中获取角色选择列表
        /// </summary>
        /// <param name="request">角色选择命令对象</param>
        /// <param name="cancellationToken">取消令牌</param>
        /// <returns>包含角色选择列表的操作结果</returns>
        public async Task<Results<List<RoleSelectOutput>>> Handle(RoleSelectCommand request, CancellationToken cancellationToken)
        {
            var roles = await _roleService.GetRolesSelect();
            return Results<List<RoleSelectOutput>>.DataResult(roles);
        }
    }
}
